package cn.springbook.cim.domain.common;

public enum Code {
	OK(200),
	CREATED(201),
	UNAUTHORIZED(401),
	FORBIDDEN(403),
	NOTFOUND(404),
	INTERNALSERVERERROR(500);
	
	private int value = 0;
	
	private Code(int value) {
		this.value = value;
	}
	
	public static Code valueOf(int value) {    //    手写的从int到enum的转换函数
        switch (value) {
        case 200:
            return OK;
        case 201:
            return CREATED;
        case 401:
            return UNAUTHORIZED;
        case 403:
            return FORBIDDEN;
        case 404:
            return NOTFOUND;
        case 500:
        	return INTERNALSERVERERROR;
        default:
            return null;
        }
    }
	
	public int value() {
        return this.value;
    }
	
	public static void main(String[] args) {
		System.out.println(Code.FORBIDDEN.value);
	}
}
